<template>
	<view>
		<view class="content">
			<u-icon v-if="reservation" name="checkmark-circle-fill" color="#302C29" size="70"></u-icon>
			<view v-if="reservation" class="txt">预约成功</view>
			<view class="listBox" v-if="reservation">
				<view class="list">
					<view class="Lcont">
						<u-row>
							<u-col span="3">
								订单编号：
							</u-col>
							<u-col span="9">
								<view class="conts fw">{{orderInfo.orderNo}}</view>
							</u-col>
						</u-row>
						<u-row>
							<u-col span="3">
								预约时间：
							</u-col>
							<u-col span="9">
								<view class="conts">
									{{orderInfo.createTime}}
								</view>
							</u-col>
						</u-row>
						<u-row>
							<u-col span="3">
								门店名称：
							</u-col>
							<u-col span="9">
								<view class="conts">
									{{storeInfo.name}}
								</view>
							</u-col>
						</u-row>
						<u-row>
							<u-col span="3">
								门店地址：
							</u-col>
							<u-col span="9">
								<view class="conts">{{storeInfo.detailAddress}}</view>
							</u-col>
						</u-row>
						<u-row>
							<u-col span="3">
								联系电话：
							</u-col>
							<u-col span="9">
								<view class="conts fw">{{storeInfo.phone}}</view>
							</u-col>
						</u-row>
						<!-- <u-row>
							<u-col span="3">
								价格：
							</u-col>
							<u-col span="9">
								<view class="conts fw">￥298.00</view>
							</u-col> 
						</u-row> -->
					</view>
				</view>
			</view>


			<view class="ubtns" v-if="reservation && orderInfo.isPay">
				<u-button style="margin: 150rpx 25rpx 0;width: 700rpx;" @click="onClickPay" color="#302C29"
					shape="circle" text="线下支付"></u-button>
			</view>

			<view v-if="!reservation">
				预约拍摄
			</view>

			<view class="listBox" v-if="!reservation">
				<view class="list">
					<view class="Lcont">

						<u-row>
							<u-col span="3">
								拍摄数量：
							</u-col>
							<u-col span="9">
								<u-number-box v-model="captureNum" @change="valChange" integer></u-number-box>
							</u-col>
						</u-row>
					</view>
				</view>
			</view>
			<view class="listBox" v-if="!reservation">
				<view class="list">
					<view class="Lcont">

						<u-row>
							<u-col span="3">
								门店名称：
							</u-col>
							<u-col span="9">
								<view class="conts">
									{{storeInfo.name}}
								</view>
							</u-col>
						</u-row>
						<u-row>
							<u-col span="3">
								门店地址：
							</u-col>
							<u-col span="9">
								<view class="conts">{{storeInfo.detailAddress}}</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</view>

			<view class="ubtns" v-if="!reservation">
				<u-button style="margin: 150rpx 25rpx 0;width: 700rpx;" @click="onClickReservation" color="#302C29"
					shape="circle" text="立即预约"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		data
	} from '../../uni_modules/uview-ui/libs/mixin/mixin'
	import {
		parseTime
	} from '../../utils/ruoyi.js'
	export default {
		data() {
			return {
				reservation: false, // 是否是预约装填  
				orderInfo: {
					orderNo: '',
					createTime: '',
					isPay: false
				},
				captureNum: 1,
				storeInfo: {
					name: '',
					detailAddress: '',
					phone: ''
				},
				orderId: undefined,
				storeId: undefined
			}
		},
		onLoad(res) {
			console.log('reserve', res)
			this.orderId = res.orderId
			this.storeId = res.storeId
			if (res.orderId) { // 表示有订单Id了
				this.reservation = true
				this.getOrderInfo()
			} else {
				this.checkIsReservation()
			}

			this.getStoreInfo(res.storeId)
		},
		methods: {
			valChange(e) {
				this.captureNum = e.value;
			},
			// 获取门店信息
			getStoreInfo(storeId) {
				var that = this;
				that.ran
					.request('/app-api/trade/delivery/pick-up-store/get?id=' + storeId, {}, 'GET')
					.then(res => {
						console.log('getStoreInfo', res);

						that.storeInfo = {
							name: res.data.name,
							detailAddress: res.data.detailAddress,
							phone: res.data.phone
						}
					});
			},
			// 点击立即支付
			onClickPay() {

				uni.showModal({
					title: '提示',
					content: '暂时不支持线上付款，请联系线下店员进行付款',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 点击扫码预约，调用接口提示预约成功，提示立即支付
			onClickReservation() {

				// captureNum
				// create
				let that = this
				that.ran
					.request('/app-api/system/user-model-order/create', {
						'modelNum': that.captureNum,
						"storeId": that.storeId,
						"shootingStatus": false,
						"modelingType": true,
						"isPay": false,
						"payType": false
					}, 'POST')
					.then(res => {
						console.log('checkIsReservation', res);
						if (res.code == 200 && res.data) {
							uni.showToast({
								title: "预约成功",
								duration: 2000
							});
							that.orderId = res.data
							that.getOrderInfo()
						} else {
							uni.showToast({
								title: "预约失败,请重试",
								duration: 2000,
								success() {
									uni.navigateBack({
										delta: 1
									})
								}
							});
						}
					});
			},
			// 检查是否已经有预约的订单
			checkIsReservation() {

				var that = this;
				that.ran
					.request('/app-api/system/user-model-order/page?pageNo=1&pageSize=10&status=1&shootingStatus=0', {},
						'GET')
					.then(res => {
						console.log('checkIsReservation', res);
						let dataList = res.data.list
						if (dataList && dataList.length) {
							// 表示预约成功
							let dataInfo = dataList[0]
							that.orderId = dataInfo.id
							that.reservation = true
							that.getOrderInfo()
						} else {
							// 创建订单


						}
					});

			},
			getOrderInfo() {
				var that = this;
				that.ran
					.request('/app-api/system/user-model-order/get?id=' + that.orderId, {}, 'GET')
					.then(res => {
						console.log('getOrderInfo', res);
						// createTime
						that.orderInfo.orderNo = res.data.orderNo
						that.reservation = true
						that.orderInfo.createTime = parseTime(res.data.createTime)
						that.orderInfo.isPay = res.data.isPay
					});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f8f8f8;
	}

	.content {
		padding-top: 100rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.txt {
			line-height: 100rpx;
		}
	}

	.listBox {
		border-radius: 10rpx;
		width: 700rpx;
		overflow: hidden;
		padding: 20rpx 0;
		background: #fff;
		margin: 25rpx 25rpx 0;

		.list {

			.Lcont {
				padding: 0 20rpx;
				line-height: 60rpx;
				font-size: 26rpx;

				.fw {
					font-weight: bold;
				}

				.conts {
					color: #666;
				}
			}
		}
	}
</style>